package cn.elead.chaos.remote.web.remote.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.elead.chaos.core.enums.BusinessType;
import cn.elead.chaos.framework.monitor.operlog.Log;
import cn.elead.chaos.framework.web.global.response.UnifiedReturn;
import cn.elead.chaos.mybatils.web.controller.BaseController;
import cn.elead.chaos.mybatils.web.page.TableDataInfo;
import cn.elead.chaos.sso.core.util.SsoUtils;
import cn.elead.chaos.remote.web.remote.domain.SysNotice;
import cn.elead.chaos.remote.web.remote.service.ISysNoticeService;

/**
 * 公告 信息操作处理
 * 
 * @author luopeng
 */
@UnifiedReturn
@RestController
@RequestMapping("/system/notice")
public class RemoteNoticeController extends BaseController {
	@Autowired
	private ISysNoticeService noticeService;

	/**
	 * 获取通知公告列表
	 */
	@GetMapping("/page")
	public TableDataInfo<SysNotice> page(SysNotice notice) {
		startPage();
		List<SysNotice> list = noticeService.selectNoticeList(notice);
		return getDataTable(list);
	}

	/**
	 * 根据通知公告编号获取详细信息
	 */
	@GetMapping(value = "/{noticeId}")
	public SysNotice getInfo(@PathVariable Long noticeId) {
		return noticeService.selectNoticeById(noticeId);
	}

	/**
	 * 新增通知公告
	 */
	@PostMapping
	@Log(title = "通知公告", businessType = BusinessType.INSERT)
	public int add(@Validated @RequestBody SysNotice notice) {
		notice.setCreateBy(SsoUtils.getUserName());
		return noticeService.insertNotice(notice);
	}

	/**
	 * 修改通知公告
	 */
	@PutMapping
	@Log(title = "通知公告", businessType = BusinessType.UPDATE)
	public int edit(@Validated @RequestBody SysNotice notice) {
		notice.setUpdateBy(SsoUtils.getUserName());
		return noticeService.updateNotice(notice);
	}

	/**
	 * 删除通知公告
	 */
	@DeleteMapping("/{noticeId}")
	@Log(title = "通知公告", businessType = BusinessType.DELETE)
	public int remove(@PathVariable Long noticeId) {
		return noticeService.deleteNoticeById(noticeId);
	}
}
